package cn.com.headfree.salary.service.impl;

import cn.com.headfree.entity.TSalaryInfo;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.salary.dao.SalaryDao;
import cn.com.headfree.salary.service.IPointcalculateService;
import org.apache.commons.collections.CollectionUtils;

import java.text.ParseException;
import java.util.List;

/**
 * @Description: TODO
 * @Author wcSun
 * @Date 2021/8/20
 **/
public class Singleton {
    //饿汉单例模式
    //在类加载时就完成了初始化，所以类加载较慢，但获取对象的速度快

    private static Singleton instance = new Singleton();//静态私有成员，已初始化

    private Singleton()
    {
        //私有构造函数
    }

    public static Singleton getInstance()    //静态，不用同步（类加载时已初始化，不会有多线程的问题）
    {
        return instance;
    }

    public void instailDetai(SalaryDao salaryDao, IPointcalculateService pointcalculateService, User user,Integer year) throws ParseException {
        synchronized(this){
            List<TSalaryInfo> noPointSalaryList = salaryDao.searchNoPointSalaryListByOrgId(user.getBaseOrgId(), year);
            if (CollectionUtils.isNotEmpty(noPointSalaryList)) {
                for (TSalaryInfo salaryInfo : noPointSalaryList) {
                    pointcalculateService.saveSalaryPointDeatail(user, salaryInfo);
                }
            }
        }
    }
}
